"use strict"
//用于处理用户登录登出
function login(){
    var server="";
    var username=document.getElementById("login_username").value;
    var password=document.getElementById("login_password").value;
    var xhr=new XMLHttpRequest()
    var data=new FormData();
    data.append("UID",username);
    data.append("PSWD",password);
    xhr.open("POST",server);
    xhr.onreadystatechange=function(){
        if(xhr.readyState==4){
            if(xhr.status==200){
                try{
                    let ans=JSON.parse(xhr.responseText);
                    if(ans["error"]==0){
                        alert("登录成功！");
                        setCookie("token",ans["token"],7);
                        info.close();
                    }else{
                        alert(ans["error"])
                    }
                }
                catch{
                    alert("网络错误！报文格式不对！请检查服务器地址是否正确")
                }
            }else{
                alert("网络错误！错误代码："+xhr.status)
            }
        }
    }
    xhr.send()
}